package com.example.lynandroid.fragment

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.lynandroid.*
import com.example.lynandroid.adapter.DirectoryAdapter
import com.example.lynandroid.bean.DirectoryBean

class DirectoryFragment : Fragment(R.layout.fragment_directory) {

    private val list = mutableListOf<DirectoryBean>()
    private lateinit var rec: RecyclerView;

    init {
        log("build")
    }

    @SuppressLint("NotifyDataSetChanged")
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        rec = view.findViewById(R.id.rec)
        rec.layoutManager = LinearLayoutManager(context)
        val adapter = DirectoryAdapter(requireActivity(), list)
        rec.adapter = adapter
        arguments?.getParcelableArray(KEY_DIR)?.forEach {
            list.add(it as DirectoryBean)
        }
        adapter.notifyDataSetChanged()
        log("onviewcreted")
    }
}